package com.cjzuji.rental.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.mapper.OrderMapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.LingLService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/order/lingl")
@Api(tags = "零零订单类")
//@Component
public class LingLController {

    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    LingLService lingLService;
    private static final Logger logger = LoggerFactory.getLogger(LingLController.class);
    //http://127.0.0.1:9099/order/lingl/getLlInfo
    //获取所有数据
    @PostMapping("/getLlInfo")
    @ApiOperation(value = "获取零零所有订单数据", notes = "获取零零所有订单数据")
    //@Scheduled(fixedRate = 60 * 60 * 24000)
    public List<Map<String, Object>> getLlInfo(){
        //从数据库获取
        try{
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String cookie = requestHeard.getLinglcookie();
            String token = requestHeard.getLingltoken();
            List<Map<String, Object>> result = lingLService.getLingLList(cookie, token);
            return result;
        }catch (Exception e){
            logger.error("获取零零所有订单数据失败");
            return null;
        }
    }

    //获取租用中的数据
    @PutMapping("/upDateBill")
    @ApiOperation(value = "获取零零租用中的订单数据", notes = "获取零零正在租用的订单数据")
    //@Scheduled(fixedRate = 60 * 60 * 24000)
    public List<Map<String, Object>> upDateBill(){
        //从数据库获取
        try{
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String cookie = requestHeard.getLinglcookie();
            logger.info("cookie {}", cookie);
            String token = requestHeard.getLingltoken();
            logger.info("token {}", token);
            List<Map<String, Object>> result = lingLService.upDateBillList(cookie, token);
            return result;
        }catch (Exception e){
            logger.error("获取零零正在租用的订单数据失败");
            return null;
        }
    }
    //获取逾期的数据
    @PutMapping("/getOverdue")
    //@Scheduled(fixedRate = 60 * 60 * 24000)
    @ApiOperation(value = "获取零零逾期的订单数据", notes = "获取零零逾期的订单数据")
    public List<Map<String, Object>> getOverdue() {
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", 1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String cookie = requestHeard.getLinglcookie();
            String token = requestHeard.getLingltoken();
            List<Map<String, Object>> result = lingLService.getOverdue(cookie, token);
            return result;
        } catch (Exception e) {
            logger.error("获取零零逾期的订单数据失败");
            return null;
        }
    }
}
